import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import VueClipboard from 'vue-clipboard2'
import * as echarts from 'echarts'
//导入 自定义的 全局样式表
import './assets/css/global.css'
import axios from "axios";

//设置axios请求根路径
axios.defaults.baseURL = " http://localhost:8081"

//请求拦截器
axios.interceptors.request.use(function (config) {
    config.headers.Authorization = window.sessionStorage.getItem('token');
    console.log("token: " + config.headers.Authorization)
    console.log("url:" + config.url)
    console.log("-------发送数据-------")
    console.dir(config.data, {depth: null});
    return config
}, function (error) {
    console.log(error)
})
//响应拦截器
axios.interceptors.response.use(function (res) {
    let data = res.data;
    console.log("-------接收数据-------")
    console.dir(data, {depth: null});
    return data;
}, function (error) {
    console.log("error:" + error);
    //如果状态码是401则表示没有授权
    if (error.response.status == 401) {
        console.log("errorCode:" + error.response.status);
        let returnPath = window.location.href;
        console.log("Path:" + returnPath);
        router.push({name: 'login', params: {returnPath: returnPath}});
    }

})


const mediaSrc = "http://localhost:8080/"
Vue.prototype.$srcHttp = mediaSrc;
//挂到原型对象上
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.prototype.$echarts = echarts
Vue.use(VueClipboard)
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
